<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  request.setAttribute("now",new Date());
%>

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading header">
                <h3 class="panel-title" id="title">资产使用登记表</h3>
            </div>

            <!-- BASIC FORM ELEMENTS -->
            <!--===================================================-->
            <form id="form_assetuse_input" class="panel-body form-horizontal form-padding">
                <input type="hidden" name="keyId" id="keyId" value="${assetUse.id}" />
                <input type="hidden" name="curDutyId" id="curDutyId" value=""/>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_asset_dialog_select('name','assetId')" style="color: #0a6dbd">资产名称</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="name" name="name" class="form-control" value="${assetUse.asset.name}" placeholder="请选择资产" disabled>
                        <input type="hidden" name="assetId" id="assetId" value="${assetUse.asset.id}" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">资产编号<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="assetNo" name="assetNo" class="form-control" value="${assetUse.asset.assetNo}" disabled>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">资产品牌<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="brand" name="brand" class="form-control" value="${assetUse.asset.brand}" disabled>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">规则型号<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="model" name="model" class="form-control" value="${assetUse.asset.model}" disabled>
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_departments_dialog_select('n','deptName','deptId')" style="color: #0a6dbd">使用部门</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="deptName" name="deptName" class="form-control" placeholder="请选择使用部门" disabled
                               value="${assetUse.useDepartment.name}">
                        <input type="hidden" id="deptId" name="deptId"
                               value="${assetUse.useDepartment.id}">
                    </div>
                </div>

                <div class="form-group" id="divNoticeUsers">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_member_dialog_select()" style="color: #0a6dbd">使用人</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="userName" name="userName" class="form-control" placeholder="请选择使用人" disabled
                               value="${assetUse.user.name}">
                        <input type="hidden" id="userId" name="userId"
                               value="${assetUse.user.id}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">提交人</label>
                    <div class="col-md-2">
                        <p class="form-control-static">${assetUse.creater.name}</p>
                    </div>
                    <label class="col-md-2 control-label">提交日期</label>
                    <div class="col-md-2">
                        <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${assetUse.dateApply}" /></p>
                    </div>
                </div>

                <div class="panel-footer">
                    <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                        <i class="fa fa-lg fa-mail-reply"></i> 返回
                    </a>
                    <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
                    <c:if test="${assetUse==null || assetUse.processState=='Draft'}">
                        <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
                    </c:if>
                    <c:if test="${assetUse!=null && assetUse.processState=='Backed'}">
                        <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
                    </c:if>
                </div>

            </form>
            <!--===================================================-->
            <!-- END BASIC FORM ELEMENTS -->

        </div>
    </div>
</div>

<script>
    var index = "${index}";
    var todo = "${todo}";
    var remind = "${remind}";
    var record = "${record}";
    var draft =  "${draft}";

    $(function(){
        var pdata= {
            keyId:$("#keyId").val(),
            entityName:"com.fz.us.oa.core.entity.com.AssetUse"
        };
        multiDuty(pdata);
    });
    
    // 资产选择框
    function fn_asset_dialog_select(nameField,idField) {
        __open_dialog_select('选择资产', '<%=path%>/com/asset/dialogs?category=3', function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();

                    // 获取 user
                    $('#'+idField).val(data.id);
                    $('#'+nameField).val(data.name);

                    $('#assetNo').val(data.assetNo);
                    $('#brand').val(data.brand);
                    $('#model').val(data.model);
                } else {
                    dialogRef.enableButtons();
                }
            };
            fn_dialog_asset_select(callback);
        });
    }

    // 部门选择框
    function fn_departments_dialog_select(isMulti,nameField,idField) {
        __open_dialog_select('选择部门', '<%=path%>/main/department/dialog?multi='+isMulti, function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();

                    // 获取 user
                    $('#'+idField).val(data.ids);
                    $('#'+nameField).val(data.names);
                } else {
                    dialogRef.enableButtons();
                }
            };
            fn_dialog_departments_select(callback);
        });
    }

    // 用户选择框
    function fn_member_dialog_select() {
        __open_dialog_select('选择成员', '<%=path%>/main/member/dialog', function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();

                    // 获取 user
                    $('#userId').val(data.id);
                    $('#userName').val(data.name)
                } else {
                    dialogRef.enableButtons();
                }
            };
            fn_dialog_member_select(callback);
        });
    }
    //校验
    function infoValidate() {
        var tmp = "";

        tmp = $("input#assetId").val();
        if(!tmp){
            __toastr_error("请选择资产！");
            return false;
        }

        tmp = $("input#deptId").val();
        if(!tmp){
            __toastr_error("请选择使用部门！");
            return false;
        }

        tmp = $("input#userId").val();
        if(!tmp){
            __toastr_error("请选择使用人！");
            return false;
        }

        return true;
    }

    //保存
    $("#btn-save-common").click(
            function(e) {
                __confirm_dialog("提示：","确定保存吗？",
                        function () {
                            __form_save("form_assetuse_input", "<%=path%>/com/assetUse/save",function(){
                                $("#apply-re-common").trigger("click");
                            });
                        }
                )
            }
    );

    //提交
    $("#btn-commit-common,#btn-recommit-common").click(
        function(e) {
            var $valid = infoValidate();
            if(!$valid) return false;

            __confirm_dialog("提示：","提交后填写资料不得修改，请确认是否进行提交？",
                function () {
                    __form_save("form_assetuse_input", "<%=path%>/com/assetUse/commit",function(){
                        $("#apply-re-common").trigger("click");
                    });
                }
            )
        }
    );

    //返回视图
    $("#apply-re-common").click(function(){

        if(index==1){
            loadURL("menu/dashboard",$('#page-content'));
        }else if(todo==1){
            loadURL("menu/toDo",$('#page-content'));
        }else if(remind==1){
            loadURL("menu/remind",$('#page-content'));
        }else if(record==1){
            loadURL("menu/taskRecord?type=1",$('#page-content'));
        }else if(record==2){
            loadURL("menu/taskRecord?type=2",$('#page-content'));
        }else if(draft==1){
            loadURL("menu/draft",$('#page-content'));
        }else{
            returnToHashUrl()
        }
    });

</script>
